// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import NProgress from 'nprogress' // Progress 进度条
import store from './store'
import Gui from './utils/gui_main'
import iView from 'iview'
import config from '@/config'
import {getToken} from './utils/auth'
Vue.config.prodninuctionTip = false
Vue.use(router)
Vue.use(Gui)
Vue.use(iView)
Vue.prototype.$config = config
router.beforeEach((to, from, next) => {
  var name = to.name  // 获取路由名称
  var token = getToken()
  var userId = store.state.user.userId
  console.log(store)
  if(!userId){
    store.dispatch("getUserInfo")
  }
  NProgress.start() // 开启Progress
  // store.commit("UPDATE_SIDERBAR", name)
  if (!token && name != 'login'&& name != 'register') {
    next({
      name: 'login' // 跳转到登录页
    })
  } else {
    next()
  }
})
router.afterEach(() => {
  NProgress.done() // 结束Progress
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {App}
})
